//
//  SqlStatement.h
//  Phidgets
//
//  Created by Daniel Hazelbaker on 11/19/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#ifndef __SQLSTATEMENT_H__
#define __SQLSTATEMENT_H__

#include <sqlite3.h>
#include <map>
#include <string>
#include "SqlValue.h"


class SystemDatabase;
typedef std::map<std::string, SqlValue> SqlParameters;


class SqlStatement
{
private:
    SystemDatabase *_database;
    sqlite3_stmt *_statement;
    SqlParameters _parameters;
    SqlValues _values;
    unsigned long _lastInsertID;
    
    void BindParameters();
    
public:
    SqlStatement(SystemDatabase *database, sqlite3 *db, std::string sql, SqlParameters params);
    ~SqlStatement();
    
    bool ExecuteNonQuery();
    SqlValue ExecuteScalar();
    bool NextRow();
    
    unsigned long LastInsertID() { return _lastInsertID; }
    SqlValue operator[](std::string column) { return _values[column]; }
    SqlValue operator[](const char *column) { return (*this)[std::string(column)]; }
    
    /* Prevent copying. */
    SqlStatement(const SqlStatement&);
    SqlStatement& operator=(const SqlStatement&);
};


#endif /* __SQLSTATEMENT_H__ */


